<?php
/**
 * Created by PhpStorm.
 * User: win7
 * Date: 2018/3/26
 * Time: 11:40
 */

namespace App\Library\Yunxin;

use App\Traits\YunXinTrait;
use Psy\Command\DumpCommand;

class Yunxin
{
    use YunXinTrait;

    public function test(){
        $a = $this->createUserIds(1,'测试1','','',123456,1);
        return $a;
    }

    /**
     * 判断云信返回消息
     *
     * @ author: ZUORENCI
     * @ E-mail:904725327@qq.com
     * @ date: 2018/3/26
     * @access public
     * @param  array   name    comment
     * @return array        comment
     */
    public function msg($arr = []){
        $list = array();
        if (!empty($arr['code'])){
            if ($arr['code']==200){
                $list['status'] = 1;
                $list['msg'] = '成功';
                $list['infos'] = $arr;
            }else{
                $list['status'] = 2;
                $list['msg'] = '失败';
                $list['infos'] = $arr;
            }
        }else{
            $list['status'] = 3;
            $list['msg'] = '网络错误';
        }
        return $list;
    }

    /**
     * 云信检查
     *
     * @ author: ZUORENCI
     * @ E-mail:904725327@qq.com
     * @ date: 2018/3/26
     * @access public
     * @param  int    id    用户ID
     * @return array 注册信息
     */
    public function check_yx($id){
        $info = $this->getUinfoss([$id]);
        $arr = $this->msg($info);
        return $arr;
    }

    /**
     * 云信注册
     *
     * @ author: ZUORENCI
     * @ E-mail:904725327@qq.com
     * @ date: 2018/3/26
     * @access public
     * @param  int    id    用户ID
     * @param  string    name    用户昵称
     * @param  string    img    全路径头像
     * @return array        comment
     */
    public function register_yx($id='',$name='',$img){
        $info = $this->createUserIds($id,$name,'',$img,123456,1);
        $arr = $this->msg($info);
        return $arr;
    }

    /**
     * 订单交易发送消息
     *
     * @ author: ZUORENCI
     * @ E-mail:904725327@qq.com
     * @ date: 2018/3/26
     * @access public
     * @param  mixed    name    comment
     * @param  int    $id1    买家用户ID
     * @param  int    $id2    卖家用户ID
     * @param  string    $msg1    买家给卖家发送的 订单已购买消息
     * @param  string    $msg2    卖家给买家发送的 订单已购买消息
     * @return array        comment
     */
    public function send_yx_msg($id1='',$id2='',$msg1='',$msg2=''){
        $re1 = $this->sendMsg($id1,0,$id2,0,$msg1,array("push"=>true,"roam"=>true,"history"=>true,"sendersync"=>true, "route"=>true),$msg1);
        $re2 = $this->sendMsg($id2,0,$id1,0,$msg2,array("push"=>true,"roam"=>true,"history"=>true,"sendersync"=>true, "route"=>true),$msg2);
        //$arr = $this->msg($info);
        $arr['a'] = $re1;
        $arr['b'] = $re2;
        return $arr;
    }

    public function lock_yx_msg(){
        $time1 = ceil(microtime(true)*1000)-9999999;
        $time2 = ceil(microtime(true)*1000);
        $arr = $this->querySessionMsg(2,1,$time1,$time2,100,1);
        return $arr;
    }

    /**
     * 更改云信信息
     *
     * @ author: ZUORENCI
     * @ E-mail:904725327@qq.com
     * @ date: 2018/3/26
     * @access public|private|protected
     * @param  mixed    name    comment
     * @param  int    name    comment
     * @param  string    name    comment
     * @param  bool       name    comment
     * @param  array   name    comment
     * @return void|int|string|boolean|array        comment
     */
    public function change_yx($id,$name='',$img='',$token){
        $info = $this->updateUinfo($id,$name,$img,'','','','','','');
        $this->updateUserId($id,'','',$token);
        $arr = $this->msg($info);
        return $arr;
    }
}